home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 January: Mac OS SDK / Dev.CD Jan 99 SDK1.toast / Development Kits / Mac OS USB DDK_v1.0.1 / Examples / PrinterClassDriver / PrinterClassDriver.h < prev    next >
Encoding:
C/C++ Source or Header  |  1998-09-03  |  7.7 KB  |  284 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        PrinterClassDriver.h
  3.  
  4.     Contains:    structures for PrinterClass
  5.  
  6.     Version:    
  7.  
  8. */
  9. #ifndef __PRINTERCLASSDRIVERH__
  10. #define __PRINTERCLASSDRIVERH__
  11.  
  12. #include <MacTypes.h>
  13. #include <Devices.h>
  14. #include <DriverServices.h>
  15. #include <Processes.h>
  16.  
  17. #ifndef __MIXEDMODE__
  18. #include <mixedmode.h>
  19. #endif
  20.  
  21. #include <USB.h>
  22.  
  23. #if PRAGMA_ONCE
  24. #pragma once
  25. #endif
  26.  
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30.  
  31. #if PRAGMA_IMPORT
  32. #pragma import on
  33. #endif
  34.  
  35. #if PRAGMA_STRUCT_ALIGN
  36.     #pragma options align=mac68k
  37. #elif PRAGMA_STRUCT_PACKPUSH
  38.     #pragma pack(push, 2)
  39. #elif PRAGMA_STRUCT_PACK
  40.     #pragma pack(2)
  41. #endif
  42.  
  43.  
  44. #if DEBUG
  45. #define IF_DEBUG(x)    x
  46. #else
  47. #define IF_DEBUG(x)
  48. #endif
  49.  
  50. #define kStrPrinterClass    "PrinterClass: "
  51. void DriverEntry(USBDeviceRef device, USBDeviceDescriptorPtr pDesc);
  52. void ExpertNotify(void *exNote);
  53.  
  54. #define kPrinterRetryCount    5
  55.  
  56. /* Move to sys files */
  57. #define kUSBPrintClass 7
  58. #define kUSBPrintSubClass 1
  59.  
  60. #define TRANSFER_SIZE    4096 /* ideally this is the same as VM page size */
  61.  
  62. // section 5.3 USB Device Class Definition for Printing Devices
  63. enum {
  64.     kUSBPrintClassGetDeviceID = 0,
  65.     kUSBPrintClassGetCentronicsStatus = 1,
  66.     kUSBPrintClassSoftReset = 2,
  67.     kUSBPrintClassProtocolReserved = 0,
  68.     kUSBPrintClassProtocolUnidirectional = 1,
  69.     kUSBPrintClassProtocolBidirectional = 2,
  70.     // 3..0xFE reserved for future use
  71.     kUSBPrintClassProtocolVendor = 0xFF
  72. };
  73.  
  74. enum 
  75. {
  76.     kDrvrCentronicsStatus = 3,
  77.     kDrvr1284IdString = 4,
  78.     kDrvrNumDevices = 5,
  79.     kDrvrSoftReset = 6,
  80.     kDrvrPrivateSetStorage = 128
  81. };
  82.  
  83. enum driverstages
  84. {
  85.     kUndefined = 0,
  86.     kNilCompletion,
  87.     kFindInterface,
  88.     kSetInterface,
  89.     kGetConfigurationDescriptor,
  90.     kGetFullConfiguration,
  91.     kGetCapabilityString,
  92.     kDelayGetCapability,
  93.     kGetFullCapabilityString,
  94.     kGetInterface,
  95.     kOpenBulkOutPipe,
  96.     kOpenBulkInPipe,
  97.     kEnterNameRegistry,
  98.  
  99.     kGetCentronicsStatus,
  100.     kDelayGetCentronicsStatus,
  101.  
  102.     kReturnFromDriver = 0x1000,
  103.     kRetryTransaction = 0x2000,
  104.     kAsyncTransaction = 0x4000,
  105.     kTransactionPending = 0x8000
  106. };
  107.  
  108. enum {
  109.     uppIODoneProcInfo = kRegisterBased
  110.          | RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  111.          | REGISTER_RESULT_LOCATION(kRegisterD0)
  112.          | REGISTER_ROUTINE_PARAMETER(1, kRegisterD0, SIZE_CODE(sizeof(OSErr)))
  113.          | REGISTER_ROUTINE_PARAMETER(2, kRegisterA0, SIZE_CODE(sizeof(IOParamPtr)))
  114.          | REGISTER_ROUTINE_PARAMETER(3, kRegisterA1, SIZE_CODE(sizeof(DCtlHandle))),
  115.  
  116.     uppQueueUSBReadProcInfo = kCStackBased
  117.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(IOParamPtr)))
  118.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(DCtlPtr)))
  119.          | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(struct usbPrinterPBStruct *))),
  120.  
  121.     uppQueueUSBWriteProcInfo = kCStackBased
  122.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(IOParamPtr)))
  123.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(DCtlPtr)))
  124.          | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(struct usbPrinterPBStruct *))),
  125.  
  126.     uppAbortProcInfo = kCStackBased
  127.          | RESULT_SIZE(SIZE_CODE(sizeof(OSStatus)))
  128.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(DriverRefNum)))
  129.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(struct usbPrinterPBStruct *))),
  130.  
  131.     uppControlStatusProcInfo = kCStackBased
  132.          | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(IOParamPtr)))
  133.          | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(DCtlPtr)))
  134.          | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(struct usbPrinterPBStruct *)))
  135. };
  136.  
  137. #if GENERATINGCFM
  138. typedef UniversalProcPtr    QueueUSBReadUPP;
  139. typedef UniversalProcPtr    QueueUSBWriteUPP;
  140. typedef UniversalProcPtr    IODoneUPP;
  141. typedef UniversalProcPtr    AbortUPP;
  142. typedef UniversalProcPtr    ControlStatusUPP;
  143. #else
  144. typedef ProcPtr                QueueUSBReadUPP;
  145. typedef ProcPtr                QueueUSBWriteUPP;
  146. typedef ProcPtr                IODoneUPP;
  147. typedef ProcPtr                AbortUPP;
  148. typedef ProcPtr                ControlStatusUPP;
  149. #endif
  150.  
  151. typedef struct {
  152.     OSErr        err;
  153.     IOParamPtr    pb;
  154.     DCtlPtr        ctl;
  155. } DrvrParams;
  156.  
  157. typedef union {
  158.     char            b;
  159.     struct {
  160.         unsigned    reserved0:2;
  161.         unsigned    paperError:1;
  162.         unsigned    select:1;
  163.         unsigned    notError:1;
  164.         unsigned    reserved1:3;
  165.     } status;
  166. } CentronicsStatusByte;
  167.  
  168. typedef struct usbPrinterPBStruct
  169. {
  170.     //
  171.     //    note: first element must be USBPB pb
  172.     //        since we often cast it to usbPrinterPBStruct
  173.     //
  174.     USBPB                             pb,                    // configuration block
  175.                                     out,                // map client write
  176.                                     in;                    // map client read
  177.     //
  178.     //    optional bulk in pipe
  179.     //
  180.     USBEndPointDescriptorPtr        readDescriptor;        // configuration/interface info
  181.     USBPipeRef                         readPipe;            // USB pipe reference
  182.     QueueUSBReadUPP                    qread,                // queue USB read from 68K
  183.                                     r;
  184.     RoutineDescriptor                qreadRD;            // static descriptor
  185.     DrvrParams                        readDrvr;            // currently active read
  186.     int                                readRetryCount;        // retry transactions
  187.     //
  188.     //    mandatory bulk out pipe
  189.     //
  190.     USBEndPointDescriptorPtr        writeDescriptor;    // configuration/interface info
  191.     USBPipeRef                         writePipe;            // USB pipe reference
  192.     QueueUSBWriteUPP                qwrite,                // queue USB write from 68K
  193.                                     w;
  194.     RoutineDescriptor                qwriteRD;            // static descriptor
  195.     DrvrParams                        writeDrvr;            // currently active read
  196.     int                                writeRetryCount;    // retry transactions
  197.     //
  198.     //    abort/cancel transactions
  199.     //
  200.     AbortUPP                        qabort,                // cancel from 68K DRVR
  201.                                     a;
  202.     RoutineDescriptor                qabortRD;            // static descriptor
  203.     //
  204.     //    status transactions
  205.     //
  206.     ControlStatusUPP                qstatus,            // simple status from 68K DRVR
  207.                                     s;
  208.     RoutineDescriptor                qstatusRD;            // static descriptor
  209.     DrvrParams                        statusDrvr;            // currently active status request
  210.     //
  211.     //    unit table driver names and refNums
  212.     //
  213.     DRVRHeaderHandle                hDrvr;                // detached from class driver resource file
  214.     DriverRefNum                    outRefNum;            // write unit table ref
  215.     DriverRefNum                    inRefNum;            // read unit table ref
  216.     Str255                            driverOutName;        // write driver name in unit table
  217.     Str255                            driverInName;        // read driver name in unit table
  218.     //
  219.     //    device: configuration and interface details
  220.     //
  221.     UInt8                            terminating;        // offline USS-720 device
  222.     USBDeviceRef                    device;                // USB device reference
  223.  
  224.     USBDeviceDescriptor             desc;                // copy for local reference
  225.     USBInterfaceDescriptorPtr        interface;            // copy for local reference
  226.     UInt32                            interfaceOffset;    // result/param for USB calls
  227.     UInt8                            whichAltInterface;
  228.  
  229.     Str255                            name;                // printer name in name registry
  230.  
  231.     unsigned char                    *capabilityString;    // 1284 capability string
  232.     USBConfigurationDescriptorPtr    config;                // USB configuration string
  233.  
  234.     unsigned char                    capability[256];    // capability: try not to fragment storage
  235.     unsigned char                    configuration[256];    // configuration: try not to fragment storage
  236.  
  237.     CentronicsStatusByte            centronics;
  238.     //
  239.     //    we double-buffer i/o requests into our heap, using page aligned blocks
  240.     //
  241.     UInt32                            pageWriteAlignedBufferSize,
  242.                                     pageReadAlignedBufferSize;
  243.     UInt8                            *pageWriteAlignedBuffer,
  244.                                     *pageReadAlignedBuffer,
  245.                                     malignedBuffer[ 3*TRANSFER_SIZE ];    //PrintDriverEntry assumes 3*TRANSFER_SIZE
  246.  
  247.     //
  248.     //    class driver async transactions
  249.     //
  250.     SInt32                            transDepth;            // don't nest transactions
  251.     SInt32                             retryCount;            // automatically retry transactions
  252.  
  253. };
  254.  
  255.  
  256. OSStatus OpenBulkEndpoint(struct usbPrinterPBStruct    *pPrinterPB, UInt32    refCon);
  257. OSStatus Abort( DriverRefNum refNum, struct usbPrinterPBStruct *pPrinterPB );
  258. void     ControlStatusRequests( IOParamPtr pb, DCtlPtr ctl, struct usbPrinterPBStruct *pPrinterPB );
  259. void     QueueRead( IOParamPtr pb, DCtlPtr ctl, struct usbPrinterPBStruct *pPrinterPB );
  260. void     QueueWrite( IOParamPtr pb, DCtlPtr ctl, struct usbPrinterPBStruct *pPrinterPB );
  261.  
  262. void      PrintDriverEntry(USBDeviceRef device,USBDeviceDescriptorPtr desc, USBInterfaceDescriptorPtr pInterface);
  263. OSStatus PrintDriverFinalize( void );
  264.  
  265.  
  266. #if PRAGMA_STRUCT_ALIGN
  267.     #pragma options align=reset
  268. #elif PRAGMA_STRUCT_PACKPUSH
  269.     #pragma pack(pop)
  270. #elif PRAGMA_STRUCT_PACK
  271.     #pragma pack()
  272. #endif
  273.  
  274. #ifdef PRAGMA_IMPORT_OFF
  275. #pragma import off
  276. #elif PRAGMA_IMPORT
  277. #pragma import reset
  278. #endif
  279.  
  280. #ifdef __cplusplus
  281. }
  282. #endif
  283.  
  284. #endif //__PRINTERCLASSDRIVERH__